import request from '@/utils/request';

const orderApi = {
  /**
   * 获取订单列表
   * @param {Object} params - 查询参数
   * @param {number} params.page - 页码
   * @param {number} params.limit - 每页数量
   * @param {number} [params.status] - 订单状态
   */
  getOrderList(params) {
    return request({
      url: '/api/order/list',
      method: 'GET',
      data: params,
      loading: true,
      loadingText: '加载中...'
    });
  },

  /**
   * 获取订单详情
   * @param {string} id - 订单ID
   */
  getOrderDetail(id) {
    return request({
      url: `/api/order/detail/${id}`,
      method: 'GET',
      loading: true,
      loadingText: '加载中...'
    });
  },

  /**
   * 创建订单
   * @param {Object} data - 订单数据
   * @param {string} data.addressId - 收货地址ID
   * @param {Array} data.cartIds - 购物车ID列表
   * @param {string} [data.couponId] - 优惠券ID
   * @param {string} [data.remark] - 订单备注
   */
  createOrder(data) {
    return request({
      url: '/api/order/create',
      method: 'POST',
      data,
      loading: true,
      loadingText: '提交订单中...'
    });
  },

  /**
   * 支付订单
   * @param {string} id - 订单ID
   * @param {string} [paymentMethod] - 支付方式
   */
  payOrder(id, paymentMethod = 'wechat') {
    return request({
      url: '/api/order/pay',
      method: 'POST',
      data: { id, paymentMethod },
      loading: true,
      loadingText: '支付中...'
    });
  },

  /**
   * 取消订单
   * @param {string} id - 订单ID
   */
  cancelOrder(id) {
    return request({
      url: `/api/order/cancel/${id}`,
      method: 'PUT',
      loading: true,
      loadingText: '取消中...'
    });
  },

  /**
   * 确认收货
   * @param {string} id - 订单ID
   */
  confirmOrder(id) {
    return request({
      url: `/api/order/confirm/${id}`,
      method: 'PUT',
      loading: true,
      loadingText: '确认中...'
    });
  },

  /**
   * 删除订单
   * @param {string} id - 订单ID
   */
  deleteOrder(id) {
    return request({
      url: `/api/order/delete/${id}`,
      method: 'DELETE',
      loading: true,
      loadingText: '删除中...'
    });
  },

  /**
   * 获取订单状态数量
   */
  getOrderStatusCount() {
    return request({
      url: '/api/order/statusCount',
      method: 'GET'
    });
  },

  /**
   * 获取物流信息
   * @param {string} id - 订单ID
   */
  getOrderLogistics(id) {
    return request({
      url: `/api/order/logistics/${id}`,
      method: 'GET',
      loading: true,
      loadingText: '查询中...'
    });
  },

  /**
   * 提交评价
   * @param {Object} data - 评价数据
   * @param {string} data.orderId - 订单ID
   * @param {string} data.productId - 商品ID
   * @param {number} data.rating - 评分
   * @param {string} data.content - 评价内容
   * @param {Array} [data.images] - 评价图片
   */
  submitReview(data) {
    return request({
      url: '/api/order/review',
      method: 'POST',
      data,
      loading: true,
      loadingText: '提交中...'
    });
  },

  /**
   * 获取订单结算信息
   * @param {Object} data - 结算参数
   * @param {Array} data.cartIds - 购物车ID列表
   */
  getCheckoutInfo(data) {
    return request({
      url: '/api/order/checkout',
      method: 'POST',
      data,
      loading: true,
      loadingText: '加载中...'
    });
  }
};

export default orderApi; 